//
//  FillAliViewController.m
//  CarCare
//
//  Created by ileo on 15/1/28.
//  Copyright (c) 2015年 baozun. All rights reserved.
//

#import "FillAliViewController.h"
#import "NetUser.h"

#define TOP_HEIGHT 45

@interface FillAliViewController ()

@property (nonatomic, strong) UITextField *realNameTF;
@property (nonatomic, strong) UITextField *idCardTF;
@property (nonatomic, strong) UITextField *aliTF;

@end

@implementation FillAliViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"填写支付宝信息";
    
    __weak __typeof(self) wself = self;
    [self navSetupLeftTitle:@"取消" action:^{
        [wself.view endEditing:YES];
        [wself dismissViewControllerAnimated:YES completion:nil success:NO info:nil];
    }];
    [self navSetupRightTitle:@"保存" action:^{
        [wself.view endEditing:YES];
        if ([Check isNoNull:wself.realNameTF.text] && [Check isAli:wself.aliTF.text] && [Check isIDCard:wself.idCardTF.text]) {
            [[[NetUser bindingAliWithRealName:wself.realNameTF.text alipay:wself.aliTF.text idCard:wself.idCardTF.text] requestWithLoad:RequestLoadShowLoading|RequestLoadShowErrorTips] requestSuccess:^(id JSON) {
                USERINFO.aliRealName = wself.realNameTF.text;
                USERINFO.aliIDCard = wself.idCardTF.text;
                USERINFO.aliAccount = wself.aliTF.text;
                [wself dismissViewControllerAnimated:YES completion:nil success:YES info:nil];
            }];
        }
    }];
    
    UILabel *tips1L = [Factory labelWithFrame:CGRectMake(22, 0, 200, TOP_HEIGHT) font:FONT_DEFAULT_Light(14) text:@"请填写基本信息" textColor:COLOR_HEXSTRING(@"#454545") onView:self.view textAlignment:NSTextAlignmentCenter];
    tips1L.textAlignment = NSTextAlignmentLeft;
    self.realNameTF = [self textFieldWithFrame:FactoryRectDefault(TOP_HEIGHT) type:TEXTFIELD_REALName];
    self.idCardTF = [self textFieldWithFrame:FactoryRectDefault(self.realNameTF.bottom) type:TEXTFIELD_IDCARD];
    self.aliTF = [self textFieldWithFrame:FactoryRectDefault(self.idCardTF.bottom + 12) type:TEXTFIELD_Ali];
    
    UILabel *tips2L = [Factory labelWithFrame:CGRectMake(10, self.aliTF.bottom + 15, __MAIN_WIDTH - 20, 30) font:FONT_DEFAULT_Light(12) text:@"提示：第一次提现成功后不可更改支付宝账号，提现以最后一次提交的支付宝账号为提现账号。请仔细填写。" textColor:COLOR_HEXSTRING(@"#454545") onView:self.view textAlignment:NSTextAlignmentCenter];
    tips2L.textAlignment = NSTextAlignmentLeft;
    tips2L.numberOfLines = 2;
    // Do any additional setup after loading the view.
}
- (NSInteger)textFieldMaxNumberWithTextField:(UITextField *)textField
{
    if (textField == self.realNameTF) {
        return 15;
    }
    else if (textField == self.idCardTF)
    {
        return 17;
    }
    else{
        return [super textFieldMaxNumberWithTextField:textField];
    }
    
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.realNameTF.text = USERINFO.aliRealName;
    self.idCardTF.text = USERINFO.aliIDCard;
    self.aliTF.text = USERINFO.aliAccount;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - keyboard
-(void)moveViewWhenKeyBoardChangeToHeight:(CGFloat)height WithDuiation:(NSTimeInterval)duration{
    self.scrollView.contentSize = CGSizeMake(__MAIN_WIDTH, __MAIN_HEIGHT_64 + height);
}

@end
